/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: lenovo
 * Date: 2022-05-02
 * Time: 19:32
 */
public class TestDemo {
    //递归打印实现：按顺序分别打印出1949的每位数字：1 9 4 9
    public static void main(String[] args) {
        int year = 1949;
        print(year);
    }
    public static void print(int n){
        if(n < 10){//初始条件
            System.out.print(n+" ");
        }else{
            print(n/10);
            System.out.print(n%10+" ");
        }
    }












    //递归求5的阶乘
    public static void main6(String[] args) {
        int n = 5;
        int ret = Fac(n);
        System.out.println(ret);
    }
    public static int Fac(int n){
        if(n == 1){//初始条件
            return 1;
        }
        return n*Fac(n-1);
    }








    public static int add (int x,int y){
        return x+y;
    }
    public static double add(double x,double y){
        return x+y;
    }
    public static int add(int x,int y,int z){
        return x+y+x;
    }

    public static void main5(String[] args) {
        int ret  = add(5,6);
    }









    public static void main4(String[] args) {
        int a = 10;
        int b = 20;
        System.out.println("交换前");
        System.out.println("a ="+a+" "+"b ="+b);
        swap(a,b);
        System.out.println("交换后");
        System.out.println("a ="+a+" "+"b ="+b);
    }
    public static void swap(int x, int y){
        System.out.println("交换前");
        System.out.println("x ="+x+" "+"y ="+y);
        int tmp = x;
        x = y;
        y = tmp;
        System.out.println("交换后");
        System.out.println("x ="+x+" "+"y ="+y);
    }
    public static void main3(String[] args) {
        int sum = 0;
        int ret = 1;
        for (int i = 1; i <= 5 ; i++) {
            ret*=i;
            sum+=ret;
        }
        System.out.println(sum);
    }





    public static void main2(String[] args) {
        int sum = 0;
        for(int i = 1; i <= 5; i++){
            sum += fac(i);//
        }
        System.out.println("sum = "+sum);
    }
    //求阶乘的方法
    public static int fac(int n){
        System.out.println("计算n的阶乘中n!="+n);
        int ret  = 1;
        for (int i = 1; i <= n ; i++) {
            ret*=i;
        }
        return ret;
    }








    public static boolean Prime(int n){
        for (int i = 2; i < Math.sqrt(n) ; i++) {
            if(n%i == 0){
                return false;
            }
        }
        return true;
    }

    public static void main1(String[] args) {
        int n = 5;
        boolean flag = Prime(n);
        if (flag == true){
            System.out.println(n);
        }

    }
}
